#ifndef CSVMANAGERDIALOG_H
#define CSVMANAGERDIALOG_H

#include <QDialog>
#include "sm-global.h"

namespace Ui { class CsvManagerDialog; }
class QTableView;

class CsvManagerDialog : public QDialog
{
    Q_OBJECT
public:
    enum DialogMode { ImportMode, ExportMode };
    enum Status { InvalidStatus, IntermediateStatus, ValidStatus };

    explicit CsvManagerDialog (QWidget *parent = 0);
    ~CsvManagerDialog();

    void enableExportSelectedCells (bool enable);
    QString fileName();
    SmGlobal::CellsRange cellsRange();
    SmGlobal::ColumnsVisibility columnsVisibility();
    bool withHeader();
    QTextCodec* codec();
    QChar separator();
    bool forceNumbersFormat();

public slots:
    void initialize();
    void setDialogMode (DialogMode dialogMode);
    void setTableView (QTableView* tableView);
    void setVisible (bool visible);
    void accept();

signals:
    void notifyWarning (QString title, QString description);
    void notifyInformation (QString title, QString description);

private slots:
    void browseFiles();
    void toggleOptions();
    void showOptions();
    void hideOptions();
    void validateFileName (const QString& fileName);
    void validateSeparator (const QString& separator);
    void tryActivateButtons();
    void saveSettings();

private:
    void setupAppearance();
    void setupCodecs();
    void setupWidgetsSizes();
    void setupConnections();
    void loadSettings();
    void setFileNameStatus (const QString& statusText, const Status status);
    void setSeparatorStatus (const QString& status, bool isValid);

    Ui::CsvManagerDialog *ui;
    QString m_documentsPath;
    QString m_showOptionsText;
    QString m_hideOptionsText;
    bool m_optionsVisible;
    bool m_fileNameIsValid;
    bool m_separatorIsValid;
    DialogMode m_dialogMode;
    bool m_canExportSelectedCells;
    int m_heightWhenOptionsHidden;
    QPixmap m_invalidStatusPixmap;
    QPixmap m_validStatusPixmap;
    int m_pixmapSize;
    bool m_shownOnce;
    bool m_openWithOptionsVisible;
    const QTableView* m_tableView;
};

#endif // CSVMANAGERDIALOG_H
